layui.use(['element', 'layer'], function () {
  var element = layui.element
    , layer = layui.layer;
  element.on('tab(docDemoTabBrief)', function (data) {
    layer.msg('切到到了' + data.index + '：' + this.innerHTML);
  });
});
layui.use('laydate', function () {
  var laydate = layui.laydate;

  //执行一个laydate实例
  laydate.render({
    elem: '#datetimerev' //指定元素
    , type: 'datetime'
    , range: '~' //true
    , format: 'yyyy-MM-ddTHH:mm:ss'
  });
  laydate.render({
    elem: '#datetimesum' //指定元素
    , type: 'datetime'
    , range: '~' //true
    , format: 'yyyy-MM-ddTHH:mm:ss'
  });
  laydate.render({
    elem: '#daterev' //指定元素
    , type: 'date'
    , range: '~' //true
    , format: 'yyyy-MM-dd'
  });
  laydate.render({
    elem: '#datesum' //指定元素
    , type: 'date'
    , range: '~' //true
    , format: 'yyyy-MM-dd'
  });
  laydate.render({
    elem: '#datecount' //指定元素
    , type: 'date'
    , range: '~' //true
    , format: 'yyyy-MM-dd'
  });
  laydate.render({
    elem: '#datetime2' //指定元素
    , type: 'datetime'
    , range: '~' //true
    , format: 'yyyy-MM-ddTHH:mm:ss'
  });
  laydate.render({
    elem: '#datetime3' //指定元素
    , type: 'datetime'
    , range: '~' //true
    , format: 'yyyy-MM-ddTHH:mm:ss'
  });
});
layui.use(['table', 'form'], function () {
  var table = layui.table;
  var form = layui.form;


  //实例: 接收的发货单查询
  form.on('submit(formRev)', function (data) {
    //layer.msg(JSON.stringify(data.field));
    var urls = jsRoutes.controllers.user.KisOutStockController.outStockRevView();
    table.render({
      elem: '#demoRev',
      where: data.field
      //contentType: 'application/json'
      , method: urls.method
      , height: 710
      , url: urls.url //数据接口
      , page: true //开启分页
      , limits: [10, 20, 50, 100, 200, 500, 1000]
      , cols: [[
        //表头  {"id":var.id,"OutStockSumId":var.OutStockSumId,"FEntity":var.FEntity,
        //"FDate":var.FDate,"FGYBillNo":var.FGYBillNo,"FShopNumber":var.FShopNumber,
        //"FStockNumber":var.FStockNumber,"SumStatus":var.SumStatus}
        { field: 'id', title: 'ID', width: 110, sort: true, fixed: 'left' }
        , { field: 'OutStockSumId', title: '汇总单号', width: 170 }
        , { field: 'FEntity', title: '明细状态', width: 100, sort: true }
        , { field: 'FDate', title: '日期', width: 180 }
        , { field: 'FGYBillNo', title: '发货单号', width: 180 }
        , { field: 'FShopNumber', title: '店铺代码', width: 180, sort: true }
        , { field: 'FStockNumber', title: '仓库代码', width: 180, sort: true }
        , { field: 'SumStatus', title: '汇总状态', width: 90 }
        , { field: 'operation', title: '操作', width: 100, sort: true }
      ]]
    });
    return false;
  });
  //实例：汇总后的发货单查询
  form.on('submit(formSum)', function (data) {
    //layer.msg(JSON.stringify(data.field));
    var urls = jsRoutes.controllers.user.KisOutStockController.outStockSumView();
    table.render({
      elem: '#demoSum',
      where: data.field
      //,contentType: 'application/json'
      , method: urls.method
      , height: 710
      , url: urls.url //数据接口
      , page: true //开启分页
      , limits: [10, 20, 50, 100, 200, 500, 1000]
      , cols: [[ //表头  {"id","FEntity","FDate","FGYBillNo","FShopNumber","FStockNumber",
        //"SumInfo","KDResultID","Result","Status","operation":'operation'}
        { field: 'id', title: 'ID', width: 110, sort: true, fixed: 'left' }
        , { field: 'ossFEntity', title: '明细状态', width: 100, sort: true }
        , { field: 'ossFDate', title: '日期', width: 180 }
        , { field: 'ossFGYBillNo', title: '发货单号', width: 170 }
        , { field: 'ossFShopNumber', title: '店铺代码', width: 180, sort: true }
        , { field: 'ossFStockNumber', title: '仓库代码', width: 180, sort: true }
        , { field: 'ossSumInfo', title: '汇总信息', width: 120 }
        , { field: 'ossKDResultID', title: '金蝶单据号', width: 180 }
        , { field: 'ossResult', title: '返回结果', width: 220 }
        , { field: 'ossStatus', title: '同步状态', width: 90 }
        , { field: 'operation', title: '操作', width: 100, sort: true }
      ]]
    });
    return false;
  });
  //实例: 发货单汇总
  form.on('submit(formRevSum)', function (data) {
    layer.msg(JSON.stringify(data.field));
    var urls = jsRoutes.controllers.user.KisOutStockController.sumOutStockRev();
    table.render({
      elem: '#table-revsum',
      where: data.field
      //,contentType: 'application/json'
      , method: urls.method
      , height: 710
      , limits: [10000]
      , limit: 10000
      , url: urls.url //数据接口
      , page: true //开启分页
      , cols: [[ //表头  {"id","FEntity","FDate","FGYBillNo","FShopNumber","FStockNumber",
        //"SumInfo","KDResultID","Result","Status","operation":'operation'}
        { field: 'DateTime', title: '执行时间', width: 250, sort: true }
        , { field: 'RunTime', title: '运行时长', width: 150, sort: true }
        , { field: 'sdoCount', title: '全部汇总单数', width: 150 }
        , { field: 'KeyCount', title: '本单汇总单数', width: 150, sort: true }
        , { field: 'date', title: '发货单日期', width: 150, sort: false }
      ]]
    });
    return false;
  });
  //实例： 汇总单SEND
  form.on('submit(formSumSend)', function (data) {
    layer.msg(JSON.stringify(data.field));
    var urls = jsRoutes.controllers.user.KisOutStockController.sendOutStockSum();
    table.render({
      elem: '#table-sendsum',
      where: data.field
      //, contentType: 'application/json'
      , method: urls.method
      , height: 710
      , limits: [10000]
      , limit: 10000
      , url: urls.url //数据接口
      , page: true //开启分页
      , cols: [[ //表头  {"id","FEntity","FDate","FGYBillNo","FShopNumber","FStockNumber",
        //"SumInfo","KDResultID","Result","Status","operation":'operation'}
        { field: 'date', title: 'date', width: 250, sort: true, fixed: 'left' }
        , { field: 'RunTime', title: '执行时间', width: 150, sort: true }
        , { field: 'sdoCount', title: '单据数', width: 150, sort: true }
        , { field: 'result', title: '明细状态', width: 600, sort: true }
      ]]
    });
    return false;
  });
  // 实例： 汇总单统计
  form.on('submit(formOssCount)', function (data) {
    layer.msg(JSON.stringify(data.field));
    var urls = jsRoutes.controllers.user.KisOutStockController.ossFEntityCount();
    table.render({
      elem: '#table-OssCount',
      where: data.field
      //contentType: 'application/json'
      , method: urls.method
      , height: 710
      , url: urls.url //数据接口
      , page: true //开启分页
      , cols: [[ //表头  {"id","FEntity","FDate","FGYBillNo","FShopNumber","FStockNumber",
        //"SumInfo","KDResultID","Result","Status","operation":'operation'}
        { field: 'date', title: '日期', width: 120, sort: true, fixed: 'left' }
        , { field: 'RunTime', title: '执行时间', width: 120, sort: true }
        , { field: 'sdoCount', title: '单据数', width: 120, sort: true }
        , { field: 'goodsCount', title: '商品数', width: 120, sort: true }
        , { field: 'AmountCount', title: '总金额', width: 160, sort: true }
        , { field: 'sendNull', title: '未同步', width: 100, sort: true }
        , { field: 'sendTrue', title: '已同步', width: 100, sort: true }
        , { field: 'sendFalse', title: '同步失败', width: 120, sort: true }
      ]]
    });
    return false;
  });

  // 实例： 补发货单
  form.on('submit(formGetSDO)', function (data) {
    layer.msg(JSON.stringify(data.field));
    var urls = jsRoutes.controllers.user.KisOutStockController.getDataFromGy();
    table.render({
      elem: '#table-demoGetSDO',
      where: data.field
      //contentType: 'application/json'
      , method: urls.method
      , height: 710
      , url: urls.url //数据接口
      , page: true //开启分页
      , cols: [[ //表头  {"id","FEntity","FDate","FGYBillNo","FShopNumber","FStockNumber",
        //"SumInfo","KDResultID","Result","Status","operation":'operation'}
        { field: 'result', title: '执行结果', width: 550, sort: true }
      ]]
    });
    return false;
  });
  // 实例： 补退货单
  form.on('submit(formGetRGO)', function (data) {
    layer.msg(JSON.stringify(data.field));
    var urls = jsRoutes.controllers.user.KisOutStockController.getDataFromGy();
    table.render({
      elem: '#table-demoRGO',
      where: data.field
      //contentType: 'application/json'
      , method: urls.method
      , height: 710
      , url: urls.url //数据接口
      , page: true //开启分页
      , cols: [[ //表头  {"id","FEntity","FDate","FGYBillNo","FShopNumber","FStockNumber",
        //"SumInfo","KDResultID","Result","Status","operation":'operation'}
         { field: 'result', title: '执行结果', width: 550, sort: true }
      ]]
    });
    return false;
  });

});

layui.use('form', function () {
  var form = layui.form;

  //监听提交
  form.on('submit(formDemo)', function (data) {
    layer.msg(JSON.stringify(data.field));
    return false;
  });
});

